import Request from '@/utils/request'
import type { GetFileListResponseType } from '@/types/api/file'

// 上传文件
export const uploadFileApi = (data: { filename: string; file: File }) => {
  return Request.Upload({
    url: '/talent/upload_file',
    data
  })
}

// 获取文档列表
export const getDocListApi = (data: { key?: string }) => {
  return Request.Get<GetFileListResponseType>({
    url: '/talent/doc_list',
    data
  })
}

// 下载文件
export const downloadFileApi = (data: { fsId: number }, prewview: boolean = false) => {
  return Request.Get<Blob>({
    url: '/talent/download_file',
    data,
    responseType: 'blob',
    download: !prewview
  })
}

// 重命名文件
export const renameFileApi = (data: { path: string; newName: string }) => {
  return Request.Post({
    url: '/talent/rename',
    data
  })
}

// 删除文件
export const deleteFileApi = (data: { path: string }) => {
  return Request.Delete({
    url: '/talent/delete',
    data
  })
}

// 上传预检
export const uploadPrepare = (data: { filename: string; md5: string }) => {
  return Request.Get<{ exist: boolean; chunks: number[] }>({
    url: '/talent/upload_prepare',
    data
  })
}

// 上传chunks
export const mutipartUploadApi = (data: {
  file: Blob
  filename: string
  chunkIndex: string
  md5: string
}) => {
  return Request.Upload<{ count: number }>({
    url: '/talent/mutipart_upload_file',
    data
  })
}

// 合并文件
export const mergeFileApi = (data: { filename: string; md5: string }) => {
  return Request.Get({
    // url: '/talent/merge_file',
    url: '/talent/merge_file_origin',
    data
  })
}
